import 'package:detect/utils/global.dart';
import 'package:flutter/material.dart';

class LoadingWidget extends StatelessWidget {
  final String? desc;
  final Color? color;
  final Color? backgroundColor;

  const LoadingWidget({super.key, this.desc = '努力加载中', this.color = Colors.white, this.backgroundColor = Colors.black});

  @override
  Widget build(BuildContext context) {
    List<Widget> children = [
      SizedBox(
        width: Global.ds(60),
        height: Global.ds(60),
        child: CircularProgressIndicator(strokeWidth: Global.ds(5), valueColor: AlwaysStoppedAnimation(color)),
      )
    ];
    if (desc?.isNotEmpty ?? false) {
      children.addAll([Container(margin: EdgeInsets.only(top: Global.ds(20)), child: Text(desc!, style: TextStyle(color: color, fontSize: Global.ds(20))))]);
    }
    return Center(
      child: Container(
        clipBehavior: Clip.antiAlias,
        padding: EdgeInsets.symmetric(horizontal: Global.ds(30), vertical: Global.ds(20)),
        decoration: BoxDecoration(color: backgroundColor, borderRadius: BorderRadius.circular(Global.ds(15))),
        child: FittedBox(fit: BoxFit.scaleDown, child: Column(mainAxisSize: MainAxisSize.min, children: children)),
      ),
    );
  }
}
